package com.wlr.blog.util.common.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.wlr.blog.util.common.enums.SearchStrategyEnum.getStrategy;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/11/14 22:20
 */
@Service
public class SearchContext<T> {
    @Value("${search.type:null}")
    private String searchType;

    @Autowired(required = false)
    private Map<String, SearchStrategy<T>> searchStrategyMap;

    public List<T> execSearch(String keywords) {
        return searchStrategyMap.get(getStrategy(searchType)).search(keywords);
    }
}
